//
//  WuTabBar.swift
//  microBlog
//
//  Created by Wu YJ on 15/11/22.
//  Copyright © 2015年 Wu YJ. All rights reserved.
//

import UIKit

 /// 难道当子控件实现了控件的方法之后，你调用父控件也是会调用子控件的方法？

class WuTabBar: UITabBar
{
    
    /**
    这个方法是在tabBar的子空间创建完之后再调用的
    */
    override func layoutSubviews()
    {
        super.layoutSubviews()
        let width = bounds.size.width / 5;

            let frame = CGRect(x: 0, y: 0, width: width, height: bounds.size.height)
            
            //记录现在是第几个了
            var index = 0
            for view in self.subviews
            {
                if view is UIControl && !(view is UIButton)
                {
                    view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
//                    index++
//                    if index == 2
//                    {
//                        index += 2
//                    }
                    index += index == 1 ? 2 : 1
                }
            }
            WuBtn.frame = CGRectOffset(frame, 2 * width, 0)
        }

    
    /**
    *  懒加载中间的点击按钮
    */
    lazy var WuBtn : UIButton =
    {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        return button
    }()


}
